package com.boyi.cycling_master.ui.base;

import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.boyi.cycling_master.common.ActivityStackManager;

import java.lang.ref.WeakReference;

import butterknife.ButterKnife;

/**
 * @author Lee_Mofeel
 * @version 1.0
 * @date 创建时间: 2017/6/21 14:48
 * @Description 所有Activity的基类 子类需要实现为实现的方法即可
 * 已知子类
 * -BaseToolBarActivity
 * -MVPBaseActivity
 */

public abstract class BaseActivity extends AppCompatActivity {

    private static final String TAG = "BaseActivity";


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 将当前的Activity添加到栈当中去
        ActivityStackManager.getInstance().addActivity(new WeakReference<Activity>(this));
        // 确定Activity间的跳转是通过bundle进行数据传递
        Bundle bundle = getIntent().getExtras();
        if (bundle != null)
            getBundleExtras(bundle);// 数据回传给子类
        // 规定执行顺序 滤掉onCreate操作
        setContentView(getContentViewId());

        initView();

        initLogic();

    }

    /**
     * 获取主布局id
     *
     * @return
     */
    public abstract int getContentViewId();

    /**
     * 初始化视图
     */
    public void initView(){
        ButterKnife.bind(this);
    }

    /**
     * 初始化业务逻辑
     */
    public abstract void initLogic();

    /**
     * 获取上个传递的bundle
     *
     * @param bundle
     */
    public abstract void getBundleExtras(Bundle bundle);

    /**
     * 销毁时需要移除返回栈中对应的activity
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 将当前Activity从栈中移除
        ActivityStackManager.getInstance().removeActivity(new WeakReference<Activity>(this));
    }


}
